--[[
  线测试,定义各种线并画出
]]

local GAME = {
  -- 需要画出的横线,[地址]=颜色
  X_LINES = {
    [0xff0711] = 0xFF000000,
    [0xff06cf] = 0xFFffffff,
    [0xff06c7] = 0xFFff0000,
  },
  -- 需要画出的竖线
  Y_LINES = {
    [0xff0713] = 0xFF000000,
    [0xff06d1] = 0xFFffffff,
    [0xff06cb] = 0xFFff0000,
  },
  -- 分辨率
  X_RESOLUTION = 224.0,
  Y_RESOLUTION = 320.0,
  -- api
  mem = manager.machine.devices[':maincpu'].spaces['program'],
  container = manager.machine.screens[":screen"].container,
  ui_container = manager.machine.render.ui_container,
}

-- 画线
function GAME.drawX()
  local x
  local k, v
  for k, v in pairs(GAME.X_LINES) do
    x = GAME.mem:read_u8(k)/GAME.X_RESOLUTION
    GAME.container:draw_line(0.0, x, 1.0, x, v)
  end
end
function GAME.drawY()
  local y
  local k, v
  for k, v in pairs(GAME.Y_LINES) do  
    y = GAME.mem:read_u8(k)/GAME.Y_RESOLUTION
    GAME.container:draw_line(y, 0.0, y, 1.0, v)
  end
end

-- 主函数
function GAME.main()
  GAME.drawX()
  GAME.drawY()
end

-- 绑定到帧运行
function GAME.run()
  emu.register_frame_done(GAME.main, "frame")
end

-- 导出到全局变量
_G.game = GAME

return GAME
